/**
 *  @Author: Yan
 *  @Date: 2020/3/11
 *  @Description: 这是移动端登录的js
 */

layui.use(['form'], function () {

    /** 回车事件*/
    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13) {
            isRightCode();
        }
    });

    /** 点击登陆*/
    $("#loginIn").on('click', function () {
        isRightCode();
    });

    /** 登陆 */
    var isRightCode = function () {
            //用户名
            var name = $("#name").val();
            if (name == "") {
                window.top.layer.alert("用户名不能为空！", {icon: 0,closeBtn: 0},function (index) {
                    $("#name").focus();
                    window.top.layer.close(index);
                });

                return;
            }
            //密码
            var pwd = $("#pwd").val();
            if (pwd == "") {
                window.top.layer.alert("密码不能为空！", {icon: 0,closeBtn: 0},function (index) {
                    $("#pwd").focus();
                    window.top.layer.close(index);
                });

                return;
            }
            //获取验证码文本框值
            var yzm_val = $("#yzm").val().trim();
            if (yzm_val == "") {
                window.top.layer.alert("验证码不能为空！", {icon: 0,closeBtn: 0},function (index) {
                    $("#yzm").focus();
                    window.top.layer.close(index);
                });
                return;
            }

            var url = PREFIX_LOGIN + "into",
                jsonData = {
                    loginName: name,
                    passWord: pwd,
                    validateCode: yzm_val
                }, loadingFun = null,
                returnFun = function (res) {
                    if (res.status == 200) {
                        window.top.location.href = PREFIX_LOGIN + "index";
                    } else {
                        window.top.layer.alert(res.message, {icon: 0,closeBtn: 0})
                    }

                };
            AjaxAction.postData(url, jsonData, loadingFun, returnFun);
        }
    ;



});